package com.song.invoicing.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.song.invoicing.mapper.ProductMapper;
import com.song.invoicing.pojo.dao.Product;
import com.song.invoicing.pojo.dao.PurchaseRecord;
import com.song.invoicing.pojo.dto.ProductQueryDTO;
import com.song.invoicing.service.ProductService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
@Service
@RequiredArgsConstructor
public class ProductServiceImpl implements ProductService {
    private final ProductMapper productMapper;
    @Override
    public Map<String, Object> getProducts(ProductQueryDTO productQueryDTO) {
        PageHelper.startPage(productQueryDTO.getPage(),productQueryDTO.getPageSize());
        Page<Product> page = productMapper.getProducts(productQueryDTO);
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("total",page.getTotal());
        resultMap.put("list",page.getResult());
        return resultMap;
    }

    @Override
    public void updatePrice(Integer productId, Double price) {
        productMapper.updatePrice(productId,price);
    }
}
